var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function(t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
    instanceof Array &&
    function(t, e) {
        t.__proto__ = e
    } ||
    function(t, e) {
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
    })(t, e)
},
function(t, e) {
    function o() {
        this.constructor = t
    }
    i(t, e),
    t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
}),
a = this && this.__decorate ||
function(t, e, o, i) {
    var n, a = arguments.length,
    r = a < 3 ? e: null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
    else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
    return a > 3 && r && Object.defineProperty(e, o, r),
    r
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var r = t("AssemblyItem"),
s = t("CarConstant"),
l = t("AttributeDetailsView"),
c = t("BroadCastMessage"),
d = t("HallConstant"),
h = t("Util"),
p = t("GlobalUserData"),
u = t("Hint"),
f = t("Global"),
m = t("CarConstant"),
_ = cc._decorator,
y = _.ccclass,
g = _.property,
v = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.pfb_details = null,
        e.pfb_assemblyItem = null,
        e.lab_level = null,
        e.lab_name = null,
        e.lab_hp = null,
        e.lab_elec = null,
        e.lab_damage = null,
        e.progressBar = null,
        e.node_ItemContent = null,
        e.spr_tag = null,
        e.frame_tagArr = new Array,
        e.spr_tagIcon = null,
        e.Frame_tagIconArr = new Array,
        e.label_Info = null,
        e.label_power = null,
        e._datailsView = null,
        e._hallControl = null,
        e._itemData = null,
        e.bSellState = !1,
        e.assemblyItem = null,
        e
    }
    return n(e, t),
    e.prototype.onLoad = function() {
        this.node.active = !0
    },
    e.prototype.init = function(t) {
        this._hallControl = t
    },
    e.prototype.updateView = function(t) {
        this._itemData = t,
        this.node.active = !0,
        this.bSellState = !1,
        this.setLabelName(t),
        this.updateAttribute(t),
        this.progressBar.progress = 0,
        this.onUpdateItem(t)
    },
    e.prototype.updateAttribute = function(t) {
        if (null != t && this._itemData.uid == t.uid) {
            if (this.label_power.string = "战力：" + h.Util.getOwnItemPower(t), this.spr_tag.node.active = !0, t.type == m.Basics_Items_Type.body) switch (t.quality) {
                case f.Quality.common:
                    this.spr_tag.node.active = !1;
                break;
                case f.Quality.epic:
                    this.spr_tag.spriteFrame = this.frame_tagArr[1],
                this.setBuffInfo(t.buff);
                break;
                case f.Quality.Legendary:
                    this.spr_tag.spriteFrame = this.frame_tagArr[2];
                break;
                default: this.spr_tag.node.active = !1;
            } else this.spr_tag.node.active = !1;
            this.lab_level.string = (t.level || "1") + "级",
            cc.v3( - 132, 104),
            cc.v3( - 31, 104),
            cc.v3(69, 104),
            t.hp ? (this.lab_hp.node.parent.active = !0, this.lab_hp.string = "" + h.Util.transformHpNum(t.hp, t.level)) : this.lab_hp.node.parent.active = !1,
            t.damage ? (this.lab_damage.node.parent.active = !0, this.lab_damage.string = "" + h.Util.transformDamageNum(t.damage, t.level)) : this.lab_damage.node.parent.active = !1,
            t.elec ? (this.lab_elec.node.parent.active = !0, this.lab_elec.string = "" + t.elec) : this.lab_elec.node.parent.active = !1
        }
    },
    e.prototype.setBuffInfo = function(t) {
        if (t) switch (this.spr_tagIcon.spriteFrame = this.Frame_tagIconArr[Number(t.buffType)], t.type) {
            case s.Basics_Items_Type.body:
                this.label_Info.string = m.getBodyData(t.id).name + "+" + Math.round(100 * (t.number - 1)) + "%";
            break;
            case s.Basics_Items_Type.wheel:
                this.label_Info.string = m.getWheelData(t.id).name + "+" + Math.round(100 * (t.number - 1)) + "%";
            break;
            case s.Basics_Items_Type.weapon:
                this.label_Info.string = m.getWeaponData(t.id).name + "+" + Math.round(100 * (t.number - 1)) + "%";
            break;
            case s.Basics_Items_Type.tools:
                this.label_Info.string = m.getToolsData(t.id).name + "+" + Math.round(100 * (t.number - 1)) + "%";
        }
    },
    e.prototype.setLabelName = function(t) {
        if (t && t.type) switch (t.type) {
            case s.Basics_Items_Type.body:
                this.lab_name.string = "" + s.getBodyData(t.id).name;
            break;
            case s.Basics_Items_Type.wheel:
                this.lab_name.string = "" + s.getWheelData(t.id).name;
            break;
            case s.Basics_Items_Type.weapon:
                this.lab_name.string = "" + s.getWeaponData(t.id).name;
            break;
            case s.Basics_Items_Type.tools:
                this.lab_name.string = "" + s.getToolsData(t.id).name;
        }
    },
    e.prototype.onUpdateItem = function(t) {
        if (!this.assemblyItem) {
            var e = cc.instantiate(this.pfb_assemblyItem);
            e.position = cc.v3(0, 20, 0),
            this.node_ItemContent.addChild(e),
            this.assemblyItem = e
        }
        this.assemblyItem.getComponent(r.AssemblyItem).updateItem(null, !0, 0, t, !1, r.Assembly_Type.Attribute)
    },
    e.prototype.updateState = function() {
        this.bSellState = !this.isOwnData()
    },
    e.prototype.isOwnData = function() {
        switch (this._itemData.type) {
            case s.Basics_Items_Type.body:
                for (var t = 0; t < p.default.arrOwnBody.length; t++) if (p.default.arrOwnBody[t].uid == this._itemData.uid) return ! 0;
            return ! 1;
            case s.Basics_Items_Type.wheel:
                for (t = 0; t < p.default.arrOwnWheel.length; t++) if (p.default.arrOwnWheel[t].uid == this._itemData.uid) return ! 0;
            return ! 1;
            case s.Basics_Items_Type.weapon:
                for (t = 0; t < p.default.arrOwnWeapon.length; t++) if (p.default.arrOwnWeapon[t].uid == this._itemData.uid) return ! 0;
            return ! 1;
            case s.Basics_Items_Type.tools:
                for (t = 0; t < p.default.arrOwnTools.length; t++) if (p.default.arrOwnTools[t].uid == this._itemData.uid) return ! 0;
            return ! 1;
            default: return ! 1;
        }
    },
    e.prototype.onBtnDetails = function() {
        this.playAudio(d.Audio_ID.btn_click),
        this.bSellState ? u.default.show("此配件已经出售！") : (this._datailsView || this.createDetailsView(), this._datailsView.updateView(this._itemData))
    },
    e.prototype.createDetailsView = function() {
        var t = cc.instantiate(this.pfb_details);
        this._hallControl.node.addChild(t),
        t.setSiblingIndex(this._hallControl.node.children.length - 2),
        this._datailsView = t.getComponent(l.default),
        this._datailsView.init(this._hallControl, this)
    },
    e.prototype.playAudio = function(t) {
        this._hallControl ? this._hallControl.playAudio(t) : c.default.getInstance().SendMessage(d.Broadcast_Func.Audio, t)
    },
    a([g(cc.Prefab)], e.prototype, "pfb_details", void 0),
    a([g(cc.Prefab)], e.prototype, "pfb_assemblyItem", void 0),
    a([g(cc.Label)], e.prototype, "lab_level", void 0),
    a([g(cc.Label)], e.prototype, "lab_name", void 0),
    a([g(cc.Label)], e.prototype, "lab_hp", void 0),
    a([g(cc.Label)], e.prototype, "lab_elec", void 0),
    a([g(cc.Label)], e.prototype, "lab_damage", void 0),
    a([g(cc.ProgressBar)], e.prototype, "progressBar", void 0),
    a([g(cc.Node)], e.prototype, "node_ItemContent", void 0),
    a([g(cc.Sprite)], e.prototype, "spr_tag", void 0),
    a([g([cc.SpriteFrame])], e.prototype, "frame_tagArr", void 0),
    a([g(cc.Sprite)], e.prototype, "spr_tagIcon", void 0),
    a([g([cc.SpriteFrame])], e.prototype, "Frame_tagIconArr", void 0),
    a([g(cc.Label)], e.prototype, "label_Info", void 0),
    a([g(cc.Label)], e.prototype, "label_power", void 0),
    a([y], e)
} (cc.Component);
o.default = v